package com.edu.whty.common.tools;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 获取Spring的Bean工具类
 * 
 * @author shijiapeng
 * @date 2015年8月25日 上午9:53:52
 */
public class ApplicationUtil implements ApplicationContextAware {
	
	private static ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		ApplicationUtil.applicationContext = applicationContext;
	}

	public static Object getBean(String name) {
		return applicationContext.getBean(name);
	}
	public static <T>  T getBean(Class<T> beanClass){
		return applicationContext.getBean(beanClass);
	}
}
